<template>
  <router-view />
</template>

<script lang="ts" setup>
import { onMounted } from 'vue'
import { httpUserLogin } from '@/api/user'
import { useStore } from 'vuex'
import useCurrentInstance from "@/utils/useCurrentInstance"
import Crypoto from '@/utils/CryptoJS'
import { getSession } from '@/utils/local'
const cry: any = new Crypoto()
const { proxy } = useCurrentInstance()
const store = useStore()

// 登录
const storeLogin = (user: object) => store.commit('login', user)

const login = (params:object) => {
  httpUserLogin(params).then((res: any) => {
    if (res.code === 200) {
      storeLogin(res.data.user)
    } else {
      proxy.$router.push('/login')
    }
  })
}


onMounted(() => {
  console.log("NODE_ENV:", process.env.NODE_ENV)

  const token = getSession('token')

  if (token) {
    // 解密
    const decryptStr = cry.decrypt(token)
    const params = JSON.parse(decryptStr)
    login(params)
  }
})

</script>

<style>
html,
body {
  margin: 0;
  padding: 0;
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;

}
</style>
